﻿///////////////////////////////////////////////////////////////
//                                                           //
// Code from Arcanea Project.                                //
//                                                           //
// Please include this license part to every reproduction    //
//   of code.                                                //
//                                                           //
// This code is under Ms-RL license                          //
//                                                           //
// Please read futher information about the license,         //
//   the project (news and updates) and the                  //
//   contributors on the address :                           //
//     http://www.codeplex.com/Arcanea/                      //
//                                                           //
///////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using Arcanea.NetworkEngine.Abstract.Engines;
using System.Reflection;
using Arcanea.NetworkEngine.Concrete.Engines.Frame;
using Arcanea.NetworkEngine.Concrete.Engines.Serialisation;
using Arcanea.NetworkEngine.Concrete.Engines.Cryptage;
using Arcanea.NetworkEngine.Concrete.Engines.Compression;
using Arcanea.NetworkEngine.Concrete.Engines.Protocole;
using System.Net.Sockets;
using Arcanea.NetworkEngine.Abstract;
using Arcanea.Mediator.Exceptions;

namespace Arcanea.NetworkEngine.Concrete
{
    /// <summary>
    /// Classe permetant de creer les instances des objets utiles au moteur réseau.
    /// </summary>
    public class TCPClientOfServerNetEngine : INetEngine
    {

        public TCPClientOfServerNetEngine(NetInformationContainer container)
        {
            _protocoleEngine = new TCPClientProtocoleEngine(container);
        }

        protected override ISerialisationEngine SerialisationEngine
        {
            get 
            { 
                if (_serialisationEngine == null) _serialisationEngine = new BinarySerialisationEngine();
                return _serialisationEngine;
            }
        }

        protected override ICompressionEngine CompressionEngine
        {
            get 
            {
                if (_compressionEngine == null) _compressionEngine = new DeflateCompressionEngine();
                return _compressionEngine;
            }
        }

        protected override ICryptageEngine CryptageEngine
        {
            get 
            {
                if (_cryptageEngine == null) _cryptageEngine = new NoneCryptageEngine();
                return _cryptageEngine;
            }
        }

        protected override IFrameEngine FrameEngine
        {
            get 
            {
                if (_frameEngine == null) _frameEngine = new SimpleTCPFrameEngine();
                return _frameEngine;
            }
        }

        public override IProtocoleEngine ProtocoleEngine
        {
            get 
            {
                if (_protocoleEngine == null) throw new BadFunctionUseException("Engine mal initiamlisée");
                return _protocoleEngine;
            }
        }

        public override bool Close()
        {
            return _protocoleEngine.Close();
        }
    }
}
